﻿package com.yy.manager{
    import flash.display.*;
    import flash.media.*;
    import flash.system.*;

	/**
	 *资源管理器 
	 * @author YY
	 * 
	 */
    public class ResourceManager {
		//资源的文件域
        public static var currentDomain:ApplicationDomain;
		
		/**
		 * 
		 * @param key
		 * @return 
		 * 
		 */
        public static function getClassByName(key:String):Class{
            var cls:Class;
            if (currentDomain.hasDefinition(key)){
                cls = (currentDomain.getDefinition(key) as Class);
            } else {
                throw (new Error(("ResourceManager：指定资源不存在!" + key)));
            };
            return cls;
        }
		/**
		 *是否有该定义 
		 * @param key
		 * @return 
		 * 
		 */
        public static function hasDefine(key:String):Boolean{
            return (currentDomain.hasDefinition(key));
        }
		/**
		 * 返回一个对象
		 * @param key
		 * @return 
		 * 
		 */
        public static function getObjectByName(key:String):Object{
            var cls:Class = getClassByName(key);
            var obj:Object = new cls();
            return obj;
        }
		/**
		 * 返回一个显示对象对象
		 * @param key
		 * @return 
		 * 
		 */
        public static function getDisplayObjectByName(key:String):DisplayObject{
            var cls:Class = getClassByName(key);
            var obj:DisplayObject = new cls();
            return obj;
        }
		/**
		 *活得得一个声音 
		 * @param key
		 * @return 
		 * 
		 */
        public static function getSoundByName(key:String):Sound{
            var cls:Class = getClassByName(key);
            var s:Sound = new cls() as Sound;
            return s;
        }
		/**
		 *获得一个按钮 
		 * @param key
		 * @return 
		 * 
		 */
        public static function getSimpleButtonByName(key:String):SimpleButton{
            var cls:Class = getClassByName(key);
            var sb:SimpleButton = new cls() as SimpleButton;
            return sb;
        }
		/**
		 * 获得一个sprite
		 * @param key
		 * @return 
		 * 
		 */
        public static function getSpriteByName(key:String):Sprite{
            var cls:Class = getClassByName(key);
            var sp:Sprite = new cls() as Sprite;
            return sp;
        }
		/**
		 *获得一个bigmap 
		 * @param key
		 * @return 
		 * 
		 */
        public static function getBitMapByName(key:String):Bitmap{
            var cls:Class = getClassByName(key);
            var bmp:Bitmap = new cls() as Bitmap;
            return bmp;
        }
		/**
		 *获得一个mc 
		 * @param key
		 * @return 
		 * 
		 */
        public static function getMovieClipByName(key:String):MovieClip{
            var cls:Class = getClassByName(key);
            var mc:MovieClip = new cls() as MovieClip;
            return mc;
        }

    }
}
